package com.cdsxt.vo;

import java.io.Serializable;


/**
 * 尚学堂商城响应结构的bean
 */
public class ResponseResultVo implements Serializable{

	/**
	 * 状态列表
	 * 
	 * 状态码
	 * 200 执行成功 
	 * 400 执行失败 知道失败原因
	 * 500 执行错误 未知的原因=有异常消息
	 * 
	 */
	// 响应业务状态码：这里模仿http状态码，200,302,404,500等
	private Integer status;

	// 响应消息：状态的描述
	private String msg;

	// 响应中的数据
	private Object data;

	public ResponseResultVo() {

	}

	

	public ResponseResultVo(Integer status, String msg, Object data) {
		this.status = status;
		this.msg = msg;
		this.data = data;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public <Type> Type getData() {
		return (Type) data;
	}

	public void setData(Object data) {
		this.data = data;
	}
	
	
	/**
	 * 判断是否成功
	 */
	public boolean success(){
		return this.status.equals(200);
	}

	/**
	 * ------------------------------构建对象功能-------------------------------------
	 */
	// 构建结果
	public static ResponseResultVo buildResult(Integer status, String msg,
			Object data) {
		return new ResponseResultVo(status, msg, data);
	}

	// 成功结果
	public static ResponseResultVo successResult() {
		return new ResponseResultVo(200, "OK", null);
	}

	// 成功结果
	public static ResponseResultVo successResult(Object data) {
		return new ResponseResultVo(200, "OK", data);
	}
	// 成功结果
	public static ResponseResultVo successResult2(String msg) {
		return new ResponseResultVo(200, msg, null);
	}

	// 失败结果
	public static ResponseResultVo failResult(String msg) {
		return new ResponseResultVo(400, msg, null);
	}

	// 错误结果
	public static ResponseResultVo errorResult(String msg) {
		return new ResponseResultVo(500, msg, null);
	}

}
